package com.workflow.action;

import java.util.Set;

import com.common.bean.Flowtemplatebranch;
import com.common.util.PagerModel;
import com.common.util.StringToken;
import com.core.ssh2.AbstractActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.workflow.bean.Inputdept;
import com.workflow.bean.Inputdeptdetail;
import com.workflow.service.InputdeptService;
import com.workflow.service.InputdeptdetailService;

public class InputdeptdetailManagerAction extends AbstractActionSupport
		implements Preparable {
	private static final long serialVersionUID = 2159767380552506331L;

	private InputdeptService inputdeptService;
	
	private InputdeptdetailService inputdeptdetailService;
	
	private Inputdept inputdept;
	
	private Inputdeptdetail inputdeptdetail;
	
	private String inputno;
	
	private String intdetailno;
	
	private PagerModel pm;
	
	private Set cardsubtypelist;
	
	public void prepare() throws Exception {
	}
	
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String goAddInputdeptdetail() throws Exception {
		inputdept = inputdeptService.findInputdept(inputno);
		cardsubtypelist = inputdept.getCardmaintype().getCardsubtypes();
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String addInputdeptdetail() throws Exception {
		inputdept = inputdeptService.findInputdept(inputno);
		inputdeptdetail.setInputdept(inputdept);
		 
		if(StringToken.DICT_FLOWBRANCH_YES.equals(inputdept.getDatadictByBranch().getName())){
			Set<Flowtemplatebranch> set = inputdept.getFlowtemplatedetail().getFlowtemplatebranchs();
			for(Flowtemplatebranch flowtemplatebranch : set) {
				if(StringToken.DICT_FLOWBRANCH_DEF.equals(flowtemplatebranch.getDefaultrun())){//保存默认分支
					inputdeptdetail.setFlowtemplatebranch(flowtemplatebranch);
				}
				if("1".equals(flowtemplatebranch.getBranchseq())) {
					if(inputdeptdetail.getCardsubtype().equals(flowtemplatebranch.getCardsubtype())) {
						inputdeptdetail.setFlowtemplatebranch(flowtemplatebranch);
					}
				}
			}
		}
		inputdeptdetailService.addInputdeptdetail(inputdeptdetail);
		return SUCCESS;
	}
	
	public String findAllInputdeptdetail() throws Exception {
		inputdept = inputdeptService.findInputdept(inputno);
		pm = inputdeptdetailService.findInputdeptdetailForPager(inputno);
		return SUCCESS;
	}
	
	public String findInputdeptdetail() throws Exception {
		inputdeptdetail = inputdeptdetailService.findInputdeptdetail(intdetailno);
		return SUCCESS;
	}
	
	public String delInputdeptdetail() throws Exception {
		inputdeptdetail = inputdeptdetailService.findInputdeptdetail(intdetailno);
		inputno = inputdeptdetail.getInputdept().getInputno();
		inputdeptdetailService.removeInputdeptdetail(intdetailno);
		return SUCCESS;
	}
	
	public String getInputdeptdetailForUpdate() throws Exception {
		inputdeptdetail = inputdeptdetailService.findInputdeptdetail(intdetailno);
		cardsubtypelist = inputdeptdetail.getInputdept().getCardmaintype().getCardsubtypes();
		return SUCCESS;
	}
	
	public String updateInputdeptdetail() throws Exception {
		inputdeptdetailService.updateInputdeptdetail(inputdeptdetail);
		inputno = inputdeptdetail.getInputdept().getInputno();
		return SUCCESS;
	}

	public Set getCardsubtypelist() {
		return cardsubtypelist;
	}

	public void setCardsubtypelist(Set cardsubtypelist) {
		this.cardsubtypelist = cardsubtypelist;
	}

	public Inputdept getInputdept() {
		return inputdept;
	}

	public void setInputdept(Inputdept inputdept) {
		this.inputdept = inputdept;
	}

	public Inputdeptdetail getInputdeptdetail() {
		return inputdeptdetail;
	}

	public void setInputdeptdetail(Inputdeptdetail inputdeptdetail) {
		this.inputdeptdetail = inputdeptdetail;
	}

	public InputdeptdetailService getInputdeptdetailService() {
		return inputdeptdetailService;
	}

	public void setInputdeptdetailService(
			InputdeptdetailService inputdeptdetailService) {
		this.inputdeptdetailService = inputdeptdetailService;
	}

	public InputdeptService getInputdeptService() {
		return inputdeptService;
	}

	public void setInputdeptService(InputdeptService inputdeptService) {
		this.inputdeptService = inputdeptService;
	}

	public String getInputno() {
		return inputno;
	}

	public void setInputno(String inputno) {
		this.inputno = inputno;
	}

	public String getIntdetailno() {
		return intdetailno;
	}

	public void setIntdetailno(String intdetailno) {
		this.intdetailno = intdetailno;
	}

	public PagerModel getPm() {
		return pm;
	}

	public void setPm(PagerModel pm) {
		this.pm = pm;
	}
	
}
